package Tkad::Draw_lines;

our @ISA = ('Tkad::Handler');

use strict;
use warnings;

sub new {
    my $package   = shift;
    my $drawing_r = shift;
    my $can       = shift;

    my $self = {
        'active'   => 0,
	'drawing'  => $drawing_r,
        'x_start'  => undef,
        'y_start'  => undef,
    };

    return bless $self, $package;
}


sub handle {
    my $self    = shift;
    my $can     = shift;
    my $ibutton = shift;
    my $x       = shift;
    my $y       = shift;

    if    ($ibutton == 1) {
        $self -> start_drawing($can, $x, $y);
    }
    elsif ($ibutton == 2) {
        $self -> stop_drawing($can, $x, $y);
    }
    return;
}

sub start_drawing {
    my $self = shift;
    my $can  = shift;
    my $x    = shift;
    my $y    = shift;

    if ($self -> {'active'} == 1) {
        $can -> createLine(
            $self -> {'x'},
            $self -> {'y'},
            $x,
            $y,
        );
    }

    $self -> {'active'} = 1;

    $self -> {'x'} = $x;
    $self -> {'y'} = $y;

    return $self;
}

sub stop_drawing {
    my $self = shift;
    
    $self -> {'active'} = 0;
    undef $self -> {'x'};
    undef $self -> {'y'};

    return new Tkad::Handler;
}

# module OK
1;


